/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Exhibitor;

import JavaClass.ActionAll;
import Main.ExpoManagerMain;
import check.check;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author Mai Lan
 */
public class ExhibitorAction {
    public  static void loadEx(JTable tbEx){
        Vector exhicp=new Vector();
        Vector exfeil=new Vector();
          exhicp.clear();
            exhicp.add("ID");
            exhicp.add("NameEx");
            exhicp.add("Company");
            exhicp.add("Money");
            exhicp.add("PaidStatus");
            exhicp.add("Email");
            exhicp.add("Phone");
            exhicp.add("Address");
            exhicp.add("confirm");
          exfeil.clear();
            exfeil.add("ID");
            exfeil.add("NameEx");
            exfeil.add("Company");
            exfeil.add("Money");
            exfeil.add("PaidStatus");
            exfeil.add("Email");
            exfeil.add("Phone");
            exfeil.add("Address");
            exfeil.add("cfirm");
          ActionAll.LoadInfor(exfeil, tbEx, exfeil, "Exhibitor");
    }
    public static  void insertEx(JTable tbex,JTextField txtNameEx,JTextField txtComEx ,JTextField txtMoneyEx,JTextField txtPaidEx ,JTextField txtEmailEx,JTextField txtPhoneEx,JTextArea teaAddEx,JComboBox cobCofim){
             boolean checkReady=check.checkReadlyData("Exhibitor","NameEx" , txtNameEx, ExpoManagerMain.conn);
             if(checkReady==false){
                    return;

             }else{
                    try {
                        String insertEx = "Insert into Exhibitor " +
                        "(NameEx,Company,Money,PaidStatus,Email,Phone,Address,cfirm) values (?,?,?,?,?,?,?,?)";
                        PreparedStatement psm = ExpoManagerMain.conn.prepareStatement(insertEx);
                        psm.setString(1, txtNameEx.getText().trim());
                        psm.setString(2, txtComEx.getText().trim());
                        psm.setString(3, txtMoneyEx.getText().trim());
                        psm.setString(4, txtPaidEx.getText().trim());
                        psm.setString(5, txtEmailEx.getText().trim());
                        psm.setString(6, txtPhoneEx.getText().trim());
                        psm.setString(7, teaAddEx.getText().trim());
                        psm.setString(8, cobCofim.getSelectedItem().toString().trim());
                        psm.executeUpdate();

                           ExhibitorAction.loadEx(tbex);

                      
                    } catch (SQLException ex) {
                        Logger.getLogger(ExhibitorAction.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
         }
    public static void UpEx(JTable tbex,JTextField txtNameEx,JTextField txtComEx ,JTextField txtMoneyEx,JTextField txtPaidEx ,JTextField txtEmailEx,JTextField txtPhoneEx,JTextArea teaAddEx,JComboBox cobCofim) {
            if(tbex.isCellSelected(tbex.getSelectedRow(), tbex.getSelectedColumn())==false){
                    JOptionPane.showMessageDialog(null, "Please choice information want to edit on list");
                    return;
            }
            else{
            
                try {
                    int n = tbex.getSelectedRow();
                    String Id = (String) tbex.getValueAt(n, 0);
                    String sqlUp = "Update Exhibitor set NameEx='" + txtNameEx.getText().trim() + "',Company='" + txtComEx.getText().trim() + "'," + "Money=" + txtMoneyEx.getText().trim() + ",PaidStatus='" + txtPaidEx.getText().trim() + "',Email='" + txtEmailEx.getText().trim() + "'," + "Phone='" + txtPhoneEx.getText().trim() + "',Address='" + teaAddEx.getText().trim() + "',cfirm='" + (String) cobCofim.getSelectedItem() + "' where ID=" + Id;
                    Statement stUp = ExpoManagerMain.conn.createStatement();
                    stUp.executeUpdate(sqlUp);
                     ExhibitorAction.loadEx(tbex);


                } catch (SQLException ex) {
                    Logger.getLogger(Exhibitor.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
    }
    public static void Del(JTable tbex)throws SQLException{
           ActionAll.deleteInfor(tbex, "Exhibitor", "ID");
           ExhibitorAction.loadEx(tbex);
    }

    
}
